package cn.com.bluemoon.daps.api.sys;

import cn.com.bluemoon.daps.api.sys.factory.RemoteSystemDatasourceServiceFallbackFactory;
import cn.com.bluemoon.daps.common.annotation.FcApiFor;
import cn.com.bluemoon.daps.common.constant.ServiceNameConstants.DapsApiSystem;
import cn.com.bluemoon.daps.common.domain.ResultBean;
import cn.com.bluemoon.daps.common.enums.DatabaseType;
import cn.com.bluemoon.daps.system.dto.DatasourceDto;
import cn.com.bluemoon.daps.system.dto.SystemDatasourceDto;
import cn.com.bluemoon.daps.system.entity.DapSystemDatasource;
import cn.com.bluemoon.daps.system.entity.DapSystemDatasourceEnvironment;
import cn.com.bluemoon.daps.system.entity.DapSystemSchema;
import io.swagger.annotations.ApiOperation;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;

/**
 * @author Jarod.Kong
 * @date 2020/12/22 13:22
 */

@FeignClient(value = DapsApiSystem.SERVICE, fallbackFactory = RemoteSystemDatasourceServiceFallbackFactory.class)
@RequestMapping(DapsApiSystem.BASE_URI + DapsApiSystem.API_DATASOURCE)
@ApiIgnore
public interface RemoteSystemDatasourceService {

    @GetMapping("/datasource/{id}")
    @ApiOperation("查询数据信息")
    ResultBean<DapSystemDatasource> getDatasource(@PathVariable("id") String id);

    @GetMapping("/get")
    @ApiOperation("根据id获取对象")
    DapSystemDatasource getById(@RequestParam("id") String id);

    @PostMapping("/datasource/list")
    @FcApiFor(team = "数据资产团队")
    ResultBean<List<DatasourceDto>> getDatasourceList();

    @PostMapping("")
    @FcApiFor(team = "数据资产团队")
    ResultBean<List<DatasourceDto>> datasourceList(@RequestBody List<String> ids);

    @GetMapping("/get/source/info")
    ResultBean<DatasourceDto> getDatasourceInfo(@RequestParam("id") String id);

    @GetMapping("exist/environment")
    ResultBean<Boolean> isExistPreAndProEnvironment(@RequestParam("datasourceId") String datasourceId);

    @PostMapping("sys/datasource")
    @FcApiFor(team = "数据资产团队")
    ResultBean<List<SystemDatasourceDto>> getResourceBySystemId(@RequestBody List<String> systemIdList);

    @GetMapping("by/dbType")
    ResultBean<List<DapSystemDatasource>> getDatasourceByDatabaseType(@RequestParam("databaseType") DatabaseType databaseType);

    @GetMapping("schema/datasource")
    ResultBean<Map<String, List<DapSystemDatasourceEnvironment>>> getSchemaDatasourceList(@RequestParam("schemaId") String schemaId);

    @GetMapping("schema/list")
    ResultBean<List<DapSystemSchema>> getSchemaList();
}
